# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=infection-monkey
_pkgname=monkey
pkgver=v2.2.0.r3599.ga55fc8d
pkgrel=1
epoch=1
pkgdesc='Automated security testing tool for networks.'
arch=('any')
groups=('blackarch' 'blackarch-networking' 'blackarch-automation')
url='https://github.com/guardicore/monkey'
depends=('python' 'python-cryptography' 'python-cffi' 'python-ecdsa' 'aws-cli'
         'pyinstaller' 'impacket' 'python-netifaces' 'python-odict'
         'python-paramiko' 'python-psutil' 'python-pycryptodome' 'python-semver'
         'python-pyftpdlib' 'pymssql' 'python-pypykatz' 'python-pysmb'
         'python-requests' 'python-urllib3'  'python-simplejson' 'python-pypsrp'
         'python-flask-pymongo' 'python-flask-restful' 'python-boto3'
         'python-botocore' 'python-pyjwt' 'python-flask' 'python-gevent'
         'python-jsonschema' 'python-mongoengine' 'python-mongomock'
         'python-pytest' 'python-dateutil' 'python-requests-mock' 'python-ring'
         'python-stix2' 'python-six' 'python-tqdm' 'python-virtualenv'
         'python-werkzeug' 'python-wheel' 'python-flask-jwt-extended'
         'python-dpath' 'python-stix2-patterns' 'python-ldaptor'
         'python-pypubsub' 'python-marshmallow' 'python-marshmallow-enum'
         'python-pymssql' 'python-pyspnego' 'python-serpentarium'
         'python-egg-timer')
makedepends=('git')
license=('GPL-3.0-or-later')
source=("git+https://github.com/guardicore/$_pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $_pkgname

  install -dm 755 "$pkgdir/usr/share/$pkgname"
  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md

  cp -a docs/ "$pkgdir/usr/share/doc/$pkgname/"

  rm -rf *.yml *.md .g* .f* LICENSE docs/ "$_pkgname/tests/" appimage/

  cp -a * "$pkgdir/usr/share/$pkgname"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname/$_pkgname
exec python infection_monkey.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"

  cat > "$pkgdir/usr/bin/monkey-island" << EOF
#!/bin/sh
cd /usr/share/$pkgname/$_pkgname
exec python monkey_island.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/monkey-island"
}

